package cn.kc.jdbc.dao;

import cn.kc.jdbc.entity.Clazz;
import cn.kc.jdbc.utils.DruidUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import javax.sql.DataSource;
import java.sql.SQLException;

/**
 * @author mosin
 * date 2022/2/14
 * @version 1.0
 */
public class ClassDaoImpl  implements  ClassDao{

    @Override
    public Clazz findClazzByClassName(String className)  {

        DataSource dataSource = DruidUtil.getDataSource();
        QueryRunner runner = new QueryRunner(dataSource);
        String  sql = "select id,class_name as  className from class  where  class_name= ?";
        Clazz clazz = null;
        try {
            clazz = runner.query(sql, new BeanHandler<>(Clazz.class), className);
            return  clazz;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return clazz;
    }
}
